﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Aij1.Model;
using Aij1.Utils;
using Aij1.BLL;
using DevExpress.Data.Filtering;

namespace Aij1.Cms
{
    public partial class EditSpecial : AdminPage
    {
        protected P_Menu PMenu;
        protected A_Special Special;
        protected void Page_Load(object sender, EventArgs e)
        {
            int menuId = CommOp.ToInt(Request.QueryString["Id"]);

            if (menuId > 0) PMenu = XpoSession.GetObjectByKey<P_Menu>(menuId);
            if (PMenu == null)
            {
                Response.Write("没有找到菜单。");
                Response.End();
            }

            Special = XpoSession.FindObject<A_Special>(CriteriaOperator.Parse("MenuId=?", menuId));

            edtContent.SettingsImageUpload.UploadImageFolder = Config.UploadDir;
            if (!IsPostBack && !IsCallback && Special != null)
            {
                if (Special != null) edtContent.Html = Special.Content;
            }
        }

        void GetArticles()
        {
            if (Special == null) Special = new A_Special(XpoSession);
            Special.Title = PMenu.Title;
            Special.Content = edtContent.Html;
            Special.EditorId = AuthData.GetCurrentUser(XpoSession);
            Special.EditTime = DateTime.Now;
            Special.DisplayTime = DateTime.Now;
            Special.MenuId = PMenu;
        }

        protected void ASPxCallback1_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            GetArticles();
            Special.Save();
            PMenu.Url = "~/Special.aspx?Id=" + Special.Oid;
            PMenu.Save();
            e.Result = "保存成功！";
        }
    }
}